<template>
  <el-dialog
    ref="dialog"
    :title="!dataForm.Id ? '新增模型' : '修改模型'"
    :close-on-click-modal="false"
    class="full_screen_dialog"
    width="90%"
    :height="documentClientHeight"
    :visible.sync="visible"
  >
    <VueBpmn
      ref="vuebpm"
      :key="designObject.Id"
      :row-data="designObject"
      @callBackFromSub="close"
      @aftersave="aftersave"
    />
  </el-dialog>
</template>
<script>
import VueBpmn from '@/components/VueBpmn'
import { fetchList as roleFetchList } from '@/api/role'
import { fetchList as userFetchList } from '@/api/user'
export default {
  components: {
    VueBpmn
  },
  data() {
    return {
      visible: false,
      designObject: {
        processName: '',
        key: '',
        users: [],
        roles: [],
        groups: []
      },
      documentClientHeight: this.$store.state.common.documentClientHeight - 250,
      dataForm: {
        Id: ''
      }
    }
  },
  methods: {
    init(data) {
      this.designObject.processName = data.Name
      this.designObject.key = data.Code
      this.designObject.Id = data.Id
      this.designObject.Xmldata = data.Xmldata
      roleFetchList().then((data) => {
        if (data && data.code === '20000') {
          this.designObject.roles = data.data
        }
      }).then(() => {
        userFetchList().then((data) => {
          this.visible = true
          if (data && data.code === '20000') {
            this.designObject.users = data.data
          }
        })
      })
    },
    close() {
      this.visible = false
    },
    aftersave(data) {
      if (data && data.code === '20000') {
        this.$message({
          message: '操作成功',
          type: 'success',
          duration: 1500,
          onClose: () => {
            this.visible = false
            this.$emit('refreshDataList')
          }
        })
      } else {
        this.$message.error(data.msg)
      }
    }
  }
}
</script>
